package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.cdp.pboc.service.dao.PbocSpecialTradeDao;
import com.irdstudio.cdp.pboc.service.domain.PbocSpecialTrade;
import com.irdstudio.cdp.pboc.service.facade.PbocSpecialTradeService;
import com.irdstudio.cdp.pboc.service.vo.PbocSpecialTradeVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 特殊交易				<p>
 * @author ligm
 * @date 2018-12-27
 */
@Service("pbocSpecialTradeService")
public class PbocSpecialTradeServiceImpl implements PbocSpecialTradeService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocSpecialTradeServiceImpl.class);

	@Autowired
	private PbocSpecialTradeDao pbocSpecialTradeDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocSpecialTrade(PbocSpecialTradeVO inPbocSpecialTradeVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocSpecialTradeVo.toString());
		int num = 0;
		try {
			PbocSpecialTrade pbocSpecialTrade = new PbocSpecialTrade();
			beanCopy(inPbocSpecialTradeVo, pbocSpecialTrade);
			num = pbocSpecialTradeDao.insertPbocSpecialTrade(pbocSpecialTrade);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocSpecialTradeVO inPbocSpecialTradeVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocSpecialTradeVo);
		int num = 0;
		try {
			PbocSpecialTrade pbocSpecialTrade = new PbocSpecialTrade();
			beanCopy(inPbocSpecialTradeVo, pbocSpecialTrade);
			num = pbocSpecialTradeDao.deleteByPk(pbocSpecialTrade);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocSpecialTradeVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocSpecialTradeVO inPbocSpecialTradeVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocSpecialTradeVo.toString());
		int num = 0;
		try {
			PbocSpecialTrade pbocSpecialTrade = new PbocSpecialTrade();
			beanCopy(inPbocSpecialTradeVo, pbocSpecialTrade);
			num = pbocSpecialTradeDao.updateByPk(pbocSpecialTrade);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocSpecialTradeVo +"修改的数据条数为"+ num);
		return num;
	}

	/**
	 * 需求编号:2019D0519
	 * 问题编号:
	 * 开发人员: caoxin
	 * 创建日期:2019/7/19
	 * 功能描述:通过所有pids查询贷记卡，准贷记卡的所有特殊交易
	 * 修改日期:2019/7/19
	 * 修改描述:
	 */
	public PbocSpecialTradeVO queryByPk(PbocSpecialTradeVO inPbocSpecialTradeVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocSpecialTradeVo);
		try {
			PbocSpecialTrade queryPbocSpecialTrade = new PbocSpecialTrade();
			beanCopy(inPbocSpecialTradeVo, queryPbocSpecialTrade);
			PbocSpecialTrade queryRslPbocSpecialTrade = pbocSpecialTradeDao.queryByPk(queryPbocSpecialTrade);
			if (Objects.nonNull(queryRslPbocSpecialTrade)) {
				PbocSpecialTradeVO outPbocSpecialTradeVo = beanCopy(queryRslPbocSpecialTrade, new PbocSpecialTradeVO());
				logger.debug("当前查询结果为:"+ outPbocSpecialTradeVo.toString());
				return outPbocSpecialTradeVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocSpecialTradeVO> queryAllOwner(PbocSpecialTradeVO pbocSpecialTradeVo)  throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocSpecialTradeVO> list = null;
		try {
			List<PbocSpecialTrade> pbocSpecialTrades = pbocSpecialTradeDao.queryAllOwnerByPage(pbocSpecialTradeVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocSpecialTrades.size());
			pageSet(pbocSpecialTrades, pbocSpecialTradeVo);
			list = (List<PbocSpecialTradeVO>) beansCopy(pbocSpecialTrades, PbocSpecialTradeVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocSpecialTradeVO> queryAllCurrOrg(PbocSpecialTradeVO pbocSpecialTradeVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocSpecialTrade> pbocSpecialTrades = pbocSpecialTradeDao.queryAllCurrOrgByPage(pbocSpecialTradeVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocSpecialTrades.size());
		List<PbocSpecialTradeVO> list = null;
		try {
			pageSet(pbocSpecialTrades, pbocSpecialTradeVo);
			list = (List<PbocSpecialTradeVO>) beansCopy(pbocSpecialTrades, PbocSpecialTradeVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocSpecialTradeVO> queryAllCurrDownOrg(PbocSpecialTradeVO pbocSpecialTradeVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocSpecialTrade> pbocSpecialTrades = pbocSpecialTradeDao.queryAllCurrDownOrgByPage(pbocSpecialTradeVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocSpecialTrades.size());
		List<PbocSpecialTradeVO> list = null;
		try {
			pageSet(pbocSpecialTrades, pbocSpecialTradeVo);
			list = (List<PbocSpecialTradeVO>) beansCopy(pbocSpecialTrades, PbocSpecialTradeVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}
	/**
	 * 需求编号:2019D0519
	 * 问题编号:
	 * 开发人员: caoxin
	 * 创建日期:2019/7/19
	 * 功能描述:通过贷款Ids查询贷款所有特殊交易
	 * 修改日期:2019/7/19
	 * 修改描述:
	 */
//	@author:liuty
//	@date:2019/10/17
//	涉及产品:税e贷
//	功能:通过贷款Ids查询贷款所有特殊交易
//	原因:增量投产只投了接口没投实现，编译报错因此注释，不影响实际业务
//	@Override
//	public List<PbocSpecialTradeVO> selectByFIdS(List<String> fids) {
//		logger.debug("当前查询参数信息为:"+ fids);
//		List<PbocSpecialTradeVO> list = null;
//		try {
//			List<PbocSpecialTrade> pbocSpecialTrades = pbocSpecialTradeDao.selectByFIdS(fids);
//			list = (List<PbocSpecialTradeVO>) beansCopy(pbocSpecialTrades, PbocCreditStatusVO.class);
//		} catch (Exception e) {
//			logger.error("查询数据发生异常!", e);
//		}
//		return list;
//	}
}
